#!/bin/bash
# Copyright (c) 2020 Presto Labs Pte. Ltd.
# Author: donggu

set -e

source ci/buildkite/pipeline-pr/scripts/git-rev.sh

echo '# ---------------------------------------------------------------------------- #'
echo "#    Diff between $BUILDKITE_PULL_REQUEST_BASE_BRANCH($BASE) and HEAD($HEAD)   #"
echo '# ---------------------------------------------------------------------------- #'

git diff origin/$BUILDKITE_PULL_REQUEST_BASE_BRANCH...HEAD --name-only --diff-filter=ACM \
| rg -v "external|third_party|experimental|_pb2" \
| rg "(\.py)$" \
|| true

echo '# ---------------------------------------------------------------------------- #'
echo '#                                    Flake 8                                   #'
echo '# ---------------------------------------------------------------------------- #'

git diff origin/$BUILDKITE_PULL_REQUEST_BASE_BRANCH...HEAD --name-only --diff-filter=ACM \
| rg -v "external|third_party|experimental|_pb2" \
| rg "(\.py)$" \
| parallel -k --max-args 1 flake8
